package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.ServerCount;
import com.liao.bean.VisitList;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.VisitDao;
import com.liao.service.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitServiceImpl implements VisitService {

    @Autowired
    private VisitDao visitDao;


    @Override
    public PageResult<VisitList> queryVisitListByPage(Integer currentPage, Integer pageSize, String logId) throws Exception {

        PageHelper.startPage(currentPage,pageSize);

        List<VisitList> visitList1=visitDao.selectVisitListByPage(logId);
        PageInfo<VisitList> pageInfo=new PageInfo<>(visitList1);

        return new PageResult<>(0, Msg.MODULE_QUERY_SUCCESS,pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void deleteVisitById(Integer logId) throws Exception {
        visitDao.deleteVisitById(logId);
    }

    @Override
    public void addVisit(Integer logId, String goodId, String visitIp, Integer visitNum) throws Exception {
        VisitList visitList=new VisitList();
        visitList.setLogId(logId);
        visitList.setGoodId(goodId);
        visitList.setVisitIp(visitIp);
        visitList.setVisitNum(visitNum);

        visitDao.addVisit(visitList);
    }

    @Override
    public void updateVisit(Integer logId, String goodId, String visitIp, Integer visitNum) throws Exception {
        VisitList visitList=new VisitList();
        visitList.setLogId(logId);
        visitList.setGoodId(goodId);
        visitList.setVisitIp(visitIp);
        visitList.setVisitNum(visitNum);

        visitDao.updateVisit(visitList);

    }
}
